package util;

import java.lang.Comparable;

public class Month implements Comparable{
	protected String[] monthVals={"Jan","Feb","Mart","April","May","June","July","Aug","Sept","Oct","Nov","Dec"};
	protected int val;
	
	public Month(int i){setMonth(i);};
	
	//Set month value. 
	//If given value less then MIN_MONTH it will be set to MIN_MONTH. 
	//If given value more then MAX_MONTH it will be set to MAX_MONTH. 
	public void setMonth(int i)
	{
		if(val<1)
			val=1;
		if(val>monthVals.length)			
			val=monthVals.length;
		val=i;
	}
	
	//returns value of month
	public int getMonth(){return val;}

	//Returns value of month with 'name' name.
	//if there is no such name returns MAX_VAL+1
	public int getMonth(String name)	
	{
		int i=0;
		for(; i<monthVals.length; i++)
			if(name.equalsIgnoreCase(monthVals[i]))
				break;
		return i+1;
	}

	//returns value of month
	public String getMonthName(){return new String(monthVals[val-1]);}

	//returns value of month i
	public String getMonthName(int i){return new String(monthVals[i-1]);}

	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		if(o instanceof String)
		{
			int i=0;
			for(; i<monthVals.length; i++)
				if(((String)o).equalsIgnoreCase(monthVals[i]))
					break;
			if(i<monthVals.length)
				return 0;			
		}
		
		if(o instanceof Month)
			if(((Month)o).getMonth()<val)
				return 1;
			else
				if(((Month)o).getMonth()>val)
					return -1;
				else 
					return 0;
		return -100;
	}
	
	public String[] getNames(){return monthVals;};
	
}
